#include <iostream>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <strings.h>
#include <unistd.h>


int main()
{
    int sockfd = socket(AF_INET, SOCK_STREAM, 0);
    struct sockaddr_in local;
    bzero(&local, sizeof local);
    local.sin_family = AF_INET;
    local.sin_addr.s_addr = INADDR_ANY;
    local.sin_port = htons(8080);

    int n = bind(sockfd, (struct sockaddr*)&local, sizeof local);
    if (n < 0) return 1;

    n = listen(sockfd, 4);
    if (n < 0) return 2;

    
    struct sockaddr_in peer;
    bzero(&peer, sizeof peer);
    socklen_t len = sizeof peer;

    n = accept(sockfd, (struct sockaddr*)&peer, &len);
    if (n < 0) return 3;
    printf("accept a peer\n");

    while (1)
    {
    }
    
    // close(sockfd);

    return 0;
}